const app = getApp()
const $api = require('../../utils/api.js').API;
Page({
    data:{
        // latitude:'38.9375',
        // longitude:'117.3571',
        // markers: [{
        //   id: 1,
        //   latitude: '38.9375',
        //   longitude: '117.3571',
        // }],
        info:{},
        moneyArr:['面议','5k以下','5k~8k','8k~10k','10k以上'],
        imgUrl:app.globalData.imgUrl,
        cShow:false,
        tdShow:false
    }, 
    onLoad: function(e){
        wx.showLoading()
        this.getCompanyInfo(e.id)
        this.getCompanyCollection(e.id)
        this.getJobTd(e.uid)
    },
    getJobTd:function(uid){
        var data = {
            'uid':wx.getStorageSync('uid'),
            'company_uid':uid,
        }
        var that = this
        $api.get('delivery/is_true',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    tdShow:true
                })
            }
        })
    },
    getCompanyInfo:function(id){
        var data = {'id':id}
        var that = this
        $api.get('company/info',data).then(res => {
            //请求成功
            wx.hideLoading()
            if(res.data.code == 1){
                // var markers = that.data.markers
                // markers[0].latitude = res.data.data.latitude
                // markers[0].longitude = res.data.data.longitude
                that.setData({
                    // latitude:res.data.data.latitude,
                    // longitude:res.data.data.longitude,
                    // markers:markers,
                    info:res.data.data
                })
            }
        })
    },
    getCompanyCollection:function(id){
        var data = {
            'uid':wx.getStorageSync('uid'),
            'rid':id,
            'type':2
        }
        var that = this
        $api.get('collection/info',data).then(res =>{
            //请求成功
            if(res.data.code == 1){
                that.setData({
                    cShow:true
                })
            }
        })
    },
    //收藏机构
    CompanyCollection:function(){
        var that = this;
        var data = {
            'uid':wx.getStorageSync('uid'),
            'rid':this.data.info.id,
            'type':2
        }
        $api.post('collection/add',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showToast({
                    title:'岗位收藏成功!!!!',
                    duration:3000,
                    mask:true,
                    icon:'none', 
                })
                that.setData({
                    cShow:true
                })
            }
        })
    },
    onShareAppMessage: function() {
        return {
            title: this.data.info.name+"-天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    },
    toUser:function(e){
        var id = e.target.dataset.touser
        wx.navigateTo({
            url: '/pages/message/online/toCompany?touid='+id
        })
    },
    tdJob:function(){
        var data = {'uid':wx.getStorageSync('uid'),
                    'company_uid':this.data.info.uid}
        var that = this
        $api.post('delivery/add',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                wx.showToast({
                    title:'投递成功!!!!',
                    duration:3000,
                    mask:true,
                    icon:'none', 
                })
                that.setData({
                    tdShow:true
                })
            }
        })
    },
    navigate() {
        var that = this
        wx.getLocation({//获取当前经纬度
          type: 'wgs84', //返回可以用于wx.openLocation的经纬度，官方提示bug: iOS 6.3.30 type 参数不生效，只会返回 wgs84 类型的坐标信息  
          success: function (res) {
              console.log(that.data.latitude)
            wx.openLocation({//​使用微信内置地图查看位置。
              latitude:Number(that.data.latitude),//要去的纬度-地址
              longitude:Number(that.data.longitude),//要去的经度-地址
              name:that.data.info.name,
              address:that.data.info.address,
              scale:18
            })
          }
        })
    },

});